package com.example.myapplication.tack_30.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.myapplication.R;
import com.example.myapplication.tack_30.Details02Activity;
import com.example.myapplication.tack_30.DetailsActivity;
import com.example.myapplication.tack_30.ThemeActivity;
import com.example.myapplication.tack_30.data.CategoryData;
import com.example.myapplication.tack_30.data.NearData;
import com.example.myapplication.utils.Common;
import com.example.myapplication.utils.OkHttpTool;
import com.google.gson.Gson;

import java.util.List;

public class CategroyAdapter extends RecyclerView.Adapter<CategroyAdapter.My> {
    private List<CategoryData.DataDTO> list;
    private Context context;
    private View view;
    private Gson gson;
    private Callback callback;
    public CategroyAdapter(List<CategoryData.DataDTO> list, Context context,Callback callback) {
        this.list = list;
        this.context = context;
        this.callback = callback;
    }

    @NonNull
    @Override
    public My onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        view = LayoutInflater.from(context).inflate(R.layout.tack_31_categoey,null);
        return new My(view);
    }

    @Override
    public void onBindViewHolder(@NonNull My holder, int position) {
        holder.name.setText(list.get(position).getName());
        holder.name.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                callback.isReturn(list.get(position).getName());
            }
        });


    }
    public interface Callback{
        void isReturn(String name);
    }
    @Override
    public int getItemCount() {
        return list != null?list.size():0;
    }

    public class My extends RecyclerView.ViewHolder{
        private TextView name;

        public My(@NonNull View itemView) {
            super(itemView);
            name = view.findViewById(R.id.name);
        }
    }
}
